package com.hsjk.szwj.module.train.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.framework.security.core.annotations.PreAuthenticated;
import com.hsjk.szwj.module.member.api.user.dto.MemberUserRespDTO;
import com.hsjk.szwj.module.train.controller.app.vo.fission.CluePageReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.fission.CluePageRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.fission.ClueSubmitReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.fission.ClueSubmitRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.fission.InvitedUsersRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.fission.PerformanceRespVO;
import com.hsjk.szwj.module.train.convert.FissionConvert;
import com.hsjk.szwj.module.train.dal.dataobject.fission.EnrollClueDO;
import com.hsjk.szwj.module.train.service.IFissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author ec50n9
 */
@Tag(name = "应用端 - 代理分销相关接口")
@RequestMapping("/train/fission")
@RestController
@Validated
public class AppFissionController {

    @Resource
    private IFissionService fissionService;

    @PostMapping("/submit-clue")
    @Operation(summary = "提交线索")
    @PreAuthenticated
    public CommonResult<ClueSubmitRespVO> submitClue(@RequestBody @Valid ClueSubmitReqVO reqVO) {
        return CommonResult.success(fissionService.submitClue(reqVO));
    }

    @PostMapping("/page-my-clue")
    @Operation(summary = "我的线索列表")
    @PreAuthenticated
    public CommonResult<PageResult<CluePageRespVO>> pageMyClue(@RequestBody @Valid CluePageReqVO reqVO) {
        Page<EnrollClueDO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        Page<EnrollClueDO> enrollClueDOPage = fissionService.pageMyClue(page, reqVO.getKeyword());
        PageResult<CluePageRespVO> pageResult = new PageResult<>(
                FissionConvert.INSTANCE.convert(enrollClueDOPage.getRecords()),
                enrollClueDOPage.getTotal()
        );
        return CommonResult.success(pageResult);
    }

    @GetMapping("/list-my-invited-users")
    @Operation(summary = "我的邀请用户列表")
    @PreAuthenticated
    public CommonResult<List<InvitedUsersRespVO>> listMyInvitedUsers(@RequestParam(defaultValue = "") String keyword) {
        List<MemberUserRespDTO> memberUserRespDTOS = fissionService.listMyInvitedUsers(keyword);
        return CommonResult.success(FissionConvert.INSTANCE.convert2(memberUserRespDTOS));
    }

    @GetMapping("/get-my-performance")
    @Operation(summary = "我的业绩列表")
    @PreAuthenticated
    public CommonResult<PerformanceRespVO> getMyPerformance() {
        return CommonResult.success(fissionService.getMyPerformance());
    }

//    @GetMapping("/get-my-performance-detail")
//    @Operation(summary = "我的业绩详情")
//    @PreAuthenticated
//    public CommonResult<PerformanceDetailPageRespVO> getMyPerformanceDetail(PerformanceDetailReqVO reqVO) {
//        return null;
//    }
}
